# 导入neo4j官方驱动包
from neo4j import GraphDatabase


uri = "bolt://localhost:7687"
auth = ("neo4j", "12345678")
driver = GraphDatabase.driver(uri, auth=auth)
# with driver.session() as session:
#    session.run(
#        """
#            CREATE (a:User {name:'张三'}),(b:User {name:'李四'}),(c:User {name:'王五'})
#            CREATE (a)-[:FRIEND]->(b),(b)-[:FRIEND]->(c),(c)-[:FRIEND]->(a)
#        """
#    )
# driver.close()


with driver.session() as session:
    result1 = session.run(
        """
           MATCH (a:User {name:'张三'})-[:FRIEND]->(f:User)
           RETURN f.name
        """
    )
    print(result1.data())
    result2 = session.run(
        """
           MATCH (a:User {name:'张三'})-[:FRIEND*2]->(f:User)
           RETURN f.name
        """
    )
    print(result2.data())
    result3 = session.run(
        """
           MATCH (a:User {name:'张三'})-[:FRIEND*1..3]->(f:User)
           RETURN f.name
        """
    )
    print(result3.data())
driver.close()
